package na.learn.java.threads.sync;

public class Queue {
	   int exchangeValue;
	    boolean busy = false;
	    synchronized int get() {
	       if (!busy)
	          try {
	             wait();
	          } catch (InterruptedException e) {
	               System.out.println(
	                   "Get: InterruptedException");
	          }
	        System.out.println("Get: " + exchangeValue);
	         notify();
	       return exchangeValue;
	    }
	    synchronized void put (int exchangeValue) {
	       if (busy)
	          try {
	             wait();
	          } catch (InterruptedException e) {
	               System.out.println(
	                    "Put: InterruptedException");
	          }
	       this.exchangeValue = exchangeValue;
	       busy = true;
	       System.out.println("Put: " + exchangeValue);
	       notify();
	    }
	}
